using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.GamerServices;
using OilRigSumoWrestlers.NetworkTools;
using OilRigSumoWrestlers.Particles;
using OilRigSumoWrestlers.Scenes.Menu;
using RaptorEngine;
using Microsoft.Xna.Framework.Audio;
using RaptorEngine.Particles;

namespace OilRigSumoWrestlers
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Game
    {
	    GraphicsDeviceManager graphics;

        public Game1()
        {
			graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
            graphics.PreferMultiSampling = true;
            
			//Unlock FPS
            //graphics.SynchronizeWithVerticalRetrace = false;
            //IsFixedTimeStep = false;

            graphics.PreferredBackBufferWidth = 1280;
            graphics.PreferredBackBufferHeight = 720;
            graphics.ApplyChanges();

            // For Windows Live Account.
            Components.Add(new GamerServicesComponent(this));
        }

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
			// Create and add all the particleSystem that will be used in the game. 
			Dictionary<string, ParticleSystem> particleSystems = new Dictionary<string, ParticleSystem>();
			particleSystems.Add("runningOil", new RunningOil());
			particleSystems.Add("bouncingSmoke", new BouncingDust());
			particleSystems.Add("explosion", new Explosion());
			particleSystems.Add("oilTower", new OilTower());
			GameEngine.Instance.Initialize(this, particleSystems);
            
            GameEngine.Instance.Network.SetNetworkTool(new SumoNetwork(1, 2));

            base.Initialize();
        }

        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
			//Splashscreen
            SplashScreen ss = new SplashScreen();
            ss.IsActive = true;
            ss.IsVisible = true;

            GameEngine.Instance.Audio.AddSoundEffect(Content.Load<SoundEffect>("Sounds/menu_forward"), "menu_forward");
            GameEngine.Instance.Audio.AddSoundEffect(Content.Load<SoundEffect>("Sounds/menu_select"), "menu_select");
            GameEngine.Instance.Audio.AddSoundEffect(Content.Load<SoundEffect>("Sounds/menu_back"), "menu_back");
            GameEngine.Instance.Audio.AddSoundEffect(Content.Load<SoundEffect>("Sounds/explosion"), "explosion");
            GameEngine.Instance.Audio.AddSoundEffect(Content.Load<SoundEffect>("Sounds/player_hit"), "player_hit");
            GameEngine.Instance.Audio.AddSoundEffect(Content.Load<SoundEffect>("Sounds/push"), "push");
            GameEngine.Instance.Audio.AddSoundEffect(Content.Load<SoundEffect>("Sounds/push_hit"), "push_hit");
            GameEngine.Instance.Audio.AddSoundEffect(Content.Load<SoundEffect>("Sounds/run1"), "run1");
            GameEngine.Instance.Audio.AddSoundEffect(Content.Load<SoundEffect>("Sounds/run2"), "run2");
            GameEngine.Instance.Audio.AddSoundEffect(Content.Load<SoundEffect>("Sounds/run3"), "run3");
            GameEngine.Instance.Audio.AddSoundEffect(Content.Load<SoundEffect>("Sounds/run4"), "run4");
            GameEngine.Instance.Audio.AddSoundEffect(Content.Load<SoundEffect>("Sounds/run5"), "run5");
            GameEngine.Instance.Audio.AddSoundEffect(Content.Load<SoundEffect>("Sounds/run_oil"), "run_oil");
            GameEngine.Instance.Audio.AddSoundEffect(Content.Load<SoundEffect>("Sounds/wall_hit"), "wall_hit");
            GameEngine.Instance.AddScene(ss);
			GameEngine.Instance.LoadContent();
        }

        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// </summary>
        protected override void UnloadContent()
        {
        }

        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
        }

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GameEngine.Instance.Draw(gameTime);

            base.Draw(gameTime);
        }
    }
}
